package com.example.controller.carecommunity;

import com.example.bean.carecommunity.Contract;
import com.example.bean.carecommunity.SafetySystem;
import com.example.bean.carecommunity.SheQujujia;
import com.example.bean.carecommunity.Vo.SafetySystemVo;
import com.example.service.carecommunity.SafetySystemService;
import com.example.utils.Results;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/safetysystem")
@Api(tags = "安全管理信息控制器")
public class SafetySystemController {
    @Autowired
    SafetySystemService service;

    @PostMapping("/selectSafety")
    @ApiOperation(value = "查询所有",notes = "安全管理查询")
    public Results selectSafety(@RequestBody SafetySystemVo safetyvo){
        PageInfo<SafetySystem> page = service.selectSafety(safetyvo);
        List<String> zhi = service.selectNoid();
        List<Contract> xiangzhixinxi = null;
        for (String id : zhi) {
            xiangzhixinxi = service.selectZhibiao(id);
        }
        return new Results().data("page",page).data("xiangzhixinxi",xiangzhixinxi);
    }

    @GetMapping("/getRizhaoJujia")
    public Results getRizhaoJujia(){
        List<SheQujujia> list = service.getRizhaoJujia();
        return new Results().data("list",list);
    }

    @PostMapping("/addSafetySystem")
    public Results addSafetySystem(@RequestBody SafetySystem safetySystem){
        return new Results().code(service.addSafetySystem(safetySystem));
    }

    @GetMapping("/selectEditSafety/{noid}")
    public Results selectEditSafety(@PathVariable String noid){
        SafetySystem safety = service.selectEditSafety(noid);
        return new Results().data("safety",safety);
    }

    @PutMapping
    public Results editSafety(@RequestBody SafetySystem safetySystem){
        return new Results().code(service.editSafety(safetySystem));
    }

    @PostMapping("/deleteSafety")
    public Results deleselectSafetyteSafety(@RequestBody List<String> ids){
        return new Results().code(service.deleteSafety(ids));
    }
}
